//import java.io.*;
//import java.security.NoSuchProviderException;
//import java.security.SecureRandom;
//
//public class OpenPGPUtil
//{
//    public static void decryptFile(String inputFileName, String keyFileName, char[] passwd, String defaultFileName)
//            throws IOException, NoSuchProviderException
//    {
//        InputStream in = new BufferedInputStream(new FileInputStream(inputFileName));
//        InputStream keyIn = new BufferedInputStream(new FileInputStream(keyFileName));
//        decryptFile(in, keyIn, passwd, defaultFileName);
//        keyIn.close();
//        in.close();
//    }
//
//    public static void decryptFile(InputStream in, InputStream keyIn, char[] passwd, String defaultFileName)
//            throws IOException, NoSuchProviderException
//    {
//        in = PGPUtil.getDecoderStream(in);
//        try
//        {
//            JcaPGPObjectFactory pgpF = new JcaPGPObjectFactory(in);
//
//            Object o = pgpF.nextObject();
//            PGPEncryptedDataList enc;
//            PGPEncryptedDataList enc;
//            if ((o instanceof PGPEncryptedDataList)) {
//                enc = (PGPEncryptedDataList)o;
//            } else {
//                enc = (PGPEncryptedDataList)pgpF.nextObject();
//            }
//            Iterator it = enc.getEncryptedDataObjects();
//            PGPPrivateKey sKey = null;
//            PGPPublicKeyEncryptedData pbe = null;
//            PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
//                    PGPUtil.getDecoderStream(keyIn), new JcaKeyFingerprintCalculator());
//            while ((sKey == null) && (it.hasNext()))
//            {
//                pbe = (PGPPublicKeyEncryptedData)it.next();
//                sKey = PGPExampleUtil.findSecretKey(pgpSec, pbe.getKeyID(), passwd);
//            }
//            if (sKey == null) {
//                throw new IllegalArgumentException("secret key for message not found.");
//            }
//            InputStream clear = pbe.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(sKey));
//
//            JcaPGPObjectFactory plainFact = new JcaPGPObjectFactory(clear);
//
//            Object message = plainFact.nextObject();
//            for (;;)
//            {
//                if ((message instanceof PGPCompressedData))
//                {
//                    PGPCompressedData cData = (PGPCompressedData)message;
//                    JcaPGPObjectFactory pgpFact = new JcaPGPObjectFactory(cData.getDataStream());
//                    message = pgpFact.nextObject();
//                }
//                if ((message instanceof PGPLiteralData))
//                {
//                    PGPLiteralData ld = (PGPLiteralData)message;
//                    String outFileName = defaultFileName;
//                    InputStream unc = ld.getInputStream();
//                    OutputStream fOut = new BufferedOutputStream(new FileOutputStream(outFileName));
//                    Streams.pipeAll(unc, fOut);
//                    fOut.close();
//                    break;
//                }
//                if ((message instanceof PGPOnePassSignatureList)) {
//                    System.out.println("encrypted message contains a signed message - not literal data.");
//                } else if ((message instanceof PGPSignatureList)) {
//                    System.out.println("encrypted message contains a signed message - not literal data.");
//                } else {
//                    throw new PGPException("message is not a simple encrypted file - type unknown.");
//                }
//                message = plainFact.nextObject();
//            }
//            if (pbe.isIntegrityProtected())
//            {
//                if (!pbe.verify()) {
//                    System.err.println("message failed integrity check");
//                } else {
//                    System.err.println("message integrity check passed");
//                }
//            }
//            else {
//                System.err.println("no message integrity check");
//            }
//        }
//        catch (PGPException e)
//        {
//            System.err.println(e);
//            if (e.getUnderlyingException() != null) {
//                e.getUnderlyingException().printStackTrace();
//            }
//        }
//    }
//
//    public static void encryptFile(String outputFileName, String inputFileName, String encKeyFileName, boolean armor, boolean withIntegrityCheck)
//            throws IOException, NoSuchProviderException, PGPException
//    {
//        OutputStream out = new BufferedOutputStream(new FileOutputStream(outputFileName));
//        PGPPublicKey encKey = PGPExampleUtil.readPublicKey(encKeyFileName);
//        encryptFile(out, inputFileName, encKey, armor, withIntegrityCheck);
//        out.close();
//    }
//
//    public static void encryptFile(OutputStream out, String fileName, PGPPublicKey encKey, boolean armor, boolean withIntegrityCheck)
//            throws IOException, NoSuchProviderException
//    {
//        if (armor) {
//            out = new ArmoredOutputStream(out);
//        }
//        try
//        {
//            byte[] bytes = PGPExampleUtil.compressFile(fileName, 1);
//            PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(
//                    new JcePGPDataEncryptorBuilder(3).setWithIntegrityPacket(withIntegrityCheck).setSecureRandom(new SecureRandom()).setProvider("BC"));
//
//            encGen.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(encKey).setProvider("BC"));
//
//            OutputStream cOut = encGen.open(out, bytes.length);
//
//            cOut.write(bytes);
//            cOut.close();
//            if (armor) {
//                out.close();
//            }
//        }
//        catch (PGPException e)
//        {
//            System.err.println(e);
//            if (e.getUnderlyingException() != null) {
//                e.getUnderlyingException().printStackTrace();
//            }
//        }
//    }
//}